from sqlalchemy import Column, Integer, String, JSON, Identity, ForeignKey
from sqlalchemy.orm import relationship
from app.database import Base

class RebarTest(Base):
    __tablename__ = "rebar_test"

    id = Column(Integer, Identity(), primary_key=True)
    source = Column(String(50), nullable=False)
    uuid = Column(String(50), nullable=False)
    precative_num = Column(String(50), nullable=False)
    equ_num = Column(String(50), nullable=False)
    trial_date = Column(String(50), nullable=False)
    precative_date = Column(String(50), nullable=False)
    report_num = Column(String(50), nullable=False)
    bridge_name = Column(String(200), nullable=False)
    other_location = Column(String(200))
    result = Column(String(10), nullable=False)
    brand = Column(String(50), nullable=False)  # 钢筋牌号
    nominal_diameter = Column(String(50), nullable=False)  # 公称直径
    
    # 关联子表数据
    data_list = relationship("RebarData", back_populates="parent")

class RebarData(Base):
    __tablename__ = "rebar_data"

    id = Column(Integer, Identity(), primary_key=True)
    uuid = Column(String(50), nullable=False)
    sample_id = Column(Integer, nullable=False)
    klhz = Column(String(50), nullable=False)  # 抗拉荷载
    klqd = Column(String(50), nullable=False)  # 抗拉强度
    cruve = Column(String(1000))  # 力值曲线
    qfhz = Column(String(50), nullable=False)  # 屈服荷载
    qfqd = Column(String(50), nullable=False)  # 屈服强度
    parent_id = Column(String(50), nullable=False)
    test_id = Column(Integer, ForeignKey('rebar_test.id'))
    
    # 关联父表
    parent = relationship("RebarTest", back_populates="data_list") 